
use "$path\Intermediary Data\localshock_dataforReg_V2.dta",clear



drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)

drop diesel_rotterdam_euro resid_movav_diesel dprix1 

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq_MA"
keep if _m==3
drop _m

drop num_obs
gen num_obs=_n-1

capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop df_reg


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen df_reg=.


foreach i of numlist 0/15 16(2)40{
capture drop  f_prix_ht

bysort id (daten):  gen f_prix_ht=log(prix_ht[_n+`i'])-log(prix_ht[_n-1])


areg f_prix_ht d_dieselr local_shock10 m_dprix l.d_dieselr l2.d_dieselr l3.d_dieselr l4.d_dieselr l5.d_dieselr ///
		l.local_shock10  l2.local_shock10 l3.local_shock10 l4.local_shock10 l5.local_shock10 ///
	l.m_dprix  l2.m_dprix l3.m_dprix l4.m_dprix l5.m_dprix  , absorb(id)  vce(cluster daten)

	

	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[local_shock10] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[local_shock10] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht

}


keep coeff1_reg coeff2_reg coeff_c_reg  se_coeff1_reg se_coeff2_reg df_reg num_obs
gen name="BASELINE MA"
gen charact="LAGS, MA SHOCK, STATION FE, DATE CLUSTER"
keep if num_obs<=40
save "$path\Graphs_Tables\Data_FigureB1_MAdata.dta", replace




clear 
use "$path\Graphs_Tables\Data_Figure4.dta"
append using "$path\Graphs_Tables\Data_FigureB1_MAdata.dta"
sort name num_obs
gen ci_coeff1_m=coeff1_reg-1.96*se_coeff1_reg
gen ci_coeff1_p=coeff1_reg+1.96*se_coeff1_reg
gen ci_coeff2_m=coeff2_reg-1.96*se_coeff2_reg
gen ci_coeff2_p=coeff2_reg+1.96*se_coeff2_reg


local nj=30
sort num_obs
graph twoway (rarea  ci_coeff1_m ci_coeff1_p num_obs if num_obs<=`nj' & charact=="LAGS, STANDARD SHOCK, STATION FE, DATE CLUSTER", col(grey%10)) ///
(line  coeff1_reg num_obs if num_obs<=`nj' & charact=="LAGS, STANDARD SHOCK, STATION FE, DATE CLUSTER" , col(red) ) ///
(rarea  ci_coeff1_m ci_coeff1_p num_obs if num_obs<=`nj' & charact=="LAGS, MA SHOCK, STATION FE, DATE CLUSTER", col(grey%10)) ///
(line  coeff1_reg num_obs if num_obs<=`nj' & charact=="LAGS, MA SHOCK, STATION FE, DATE CLUSTER" , col(red) lpattern(dash)) ///
(rarea  ci_coeff2_m ci_coeff2_p num_obs if num_obs<=`nj' & charact=="LAGS, STANDARD SHOCK, STATION FE, DATE CLUSTER", col(grey%10)) ///
(line  coeff2_reg num_obs if num_obs<=`nj' & charact=="LAGS, STANDARD SHOCK, STATION FE, DATE CLUSTER", col(navy) ) ///
(rarea  ci_coeff2_m ci_coeff2_p num_obs if num_obs<=`nj' & charact=="LAGS, MA SHOCK, STATION FE, DATE CLUSTER", col(grey%10)) ///
(line  coeff2_reg num_obs if num_obs<=`nj' & charact=="LAGS, MA SHOCK, STATION FE, DATE CLUSTER" , col(navy) lpattern(dash) ///
legend(order(2 "Baseline" 4 "Alt. shock (MA)"  6 "Local price change - Baseline" 8 "Local price change - Alt.")) graphregion(color(white)) xtitle("Time (in days)") ytitle("Cum. Response")) ///
, xlabel(0(2)`nj') ylabel(0(0.1)1) 
graph export "$path\Graphs_Tables\FigureB1.png", replace
graph export "$path\Graphs_Tables\FigureB1.eps", replace

